<template>
  <div class="app">
    <el-row :gutter="5" class="content">
      <el-col :span="18">
        <el-card class="box-card">
          <div slot="header" class="title">试题列表</div>
          <div v-for="(subject, index) in subjects" :key="subject.subjectId">
            <h3>{{ index + 1 }}. {{ subject.subjectTitle }}</h3>
            <div v-if="subject.subjectType === 2">
              <el-checkbox-group disabled="disabled" v-model="subject.answers">
                <el-checkbox
                  v-for="option in subject.options"
                  :key="option.optionId"
                  :label="option.optionTitle"
                  style="display: flex"
                >
                  {{ option.optionTitle }}. {{ option.optionContent }}
                </el-checkbox>
              </el-checkbox-group>
            </div>
            <div v-else-if="subject.subjectType === 6">用户答案: {{ subject.answer }}</div>
            <div v-else>
              <el-radio-group disabled="disabled" v-model="subject.answer">
                <el-radio
                  v-for="option in subject.options"
                  :key="option.optionId"
                  :label="option.optionTitle"
                  style="display: flex"
                >
                  {{ option.optionTitle }}. {{ option.optionContent }}
                </el-radio>
              </el-radio-group>
            </div>
            <div v-if="subject.subjectType !== 6">正确答案: {{ subject.correctAnswer }}</div>
            <div v-if="subject.subjectType === 6">正确答案: {{ subject.textAnswer }}</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="box-card">
          <div slot="header" class="title">考试详情</div>
          <div>
            <div class="detail">{{ subjectTitle }}</div>
            <div class="score-detail">
              <div>试题总数: {{ exam.subjectCount }}</div>
              <div>答对题数: {{ exam.correctCount }}</div>
              <div v-if="moduleType !== 2">考试得分: {{ exam.score }}</div>
            </div>
            <div>
              <el-button-group>
                <el-button size="small" type="danger" @click="back">返回上级</el-button>
              </el-button-group>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { BizExamController, DictionaryController } from '@/api';
export default {
  name: 'ExamView',
  data() {
    return {
      sceneType: null,
      moduleType: null,
      personnelType: null,
      examType: null,
      exam: null,
      examLevel: 0,
      subjects: [],
      sceneTypeList: [],
      subjectTitle: '',
      record: {
        sceneType: '',
        moduleType: '',
        records: []
      }
    };
  },
  methods: {
    back() {
      if (this.moduleType === 2) {
        this.$router.replace({
          name: 'frontScene',
          query: {
            sceneType: this.sceneType,
            personnelType: this.personnelType,
            examType: this.examType
          }
        });
      } else if (this.moduleType === 3) {
        this.$router.replace({
          name: 'course',
          query: {
            sceneType: this.sceneType,
            personnelType: this.personnelType,
            examType: this.examType
          }
        });
      }
    },
    getSubjects() {
      let params = {
        personnelType: this.personnelType,
        moduleType: this.moduleType,
        materialType: this.materialType,
        sceneType: this.sceneType,
        examMode: this.examType,
        examLevel: this.examLevel
      };
      return new Promise((resolve, reject) => {
        BizExamController.detail(this, params)
          .then(res => {
            this.exam = res.data;
            this.personnelType = this.exam.personnelType;
            this.moduleType = this.exam.moduleType;
            this.sceneType = this.exam.sceneType;
            this.subjects = res.data.subjects;
            if (this.moduleType === 3 && this.exam.paperName) {
              this.subjectTitle = this.exam.paperName;
            }
          })
          .catch(e => {
            reject(e);
          });
      });
    },
    loadSceneTypeList() {
      let params = {
        dictCode: 'SceneType'
      };
      return new Promise((resolve, reject) => {
        DictionaryController.dictGlobalDict(this, params)
          .then(res => {
            resolve(res.getList());
          })
          .catch(e => {
            reject(e);
          });
      });
    }
  },
  mounted() {
    const sceneType = this.$route.query.sceneType;
    this.sceneType = sceneType;
    const moduleType = this.$route.query.moduleType;
    this.moduleType = moduleType;
    const personnelType = this.$route.query.personnelType;
    this.personnelType = personnelType;
    const examType = this.$route.query.examType;
    this.examType = examType;
    const examLevel = this.$route.query.examLevel;
    this.examLevel = examLevel;
    this.loadSceneTypeList().then(res => {
      this.sceneTypeList = res;
      if (this.moduleType === 2) {
        this.subjectTitle = this.sceneTypeList.find(s => parseInt(s.id) === this.sceneType)?.name;
      }
    });
    this.getSubjects();
  }
};
</script>

<style scoped>
.app {
  height: 100vh;
  padding: 35px;
}

.app .content {
  width: 100%;
  height: 95vh;
}

.app .content .box-card {
  width: 100%;
  height: 95vh;
  overflow-y: auto;
  word-wrap: break-word;
  overflow-wrap: break-word; /* 注意：通常 'word-wrap' 和 'overflow-wrap' 是同一个属性的别名，所以你可能只需要一个 */
}

.title {
  height: 30px;
  font-size: 16px;
  line-height: 30px;
}
.detail {
  height: 30px;
  font-size: 16px;
  font-style: italic;
  font-weight: bolder;
}
/deep/ .el-radio__label {
  white-space: normal; /* 换行 */
}

/deep/ .el-checkbox__label {
  white-space: normal; /* 换行 */
}
.score-detail > div {
  margin: 5px 0px;
  font-size: 14px;
  font-weight: bolder;
  font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei',
    '微软雅黑', Arial, sans-serif;
}
</style>
